package Review;

public class Test32 {
       public static void main(String[] args) {
    	   System.out.println(allNumberOf1(10));
    	   System.out.println(NumberOfOne.count(534));
	}
       public static int allNumberOf1(int n){
    	   if(n<1){
    		   return 0;
    	   }
    	   int count = 0;
    	   for(int i=1;i<=n;i++){
    		   count += numberOf1(i);
    	   }
    	   return count;
       }
       public static int numberOf1(int n){
    	   int number = 0;
    	   while(n!=0){
    		   if(n%10 == 1){
    			   number++;
    		   }
    		   n = n/10;
    	   }
    	   return number;
       }
}
class NumberOfOne{
	public static int count(int n){
	    if(n<1)
	        return 0;
	    int count = 0;
	    int base = 1;
	    int round = n;
	    while(round>0){
	        int weight = round%10;
	        round/=10;
	        count += round*base;
	        if(weight==1)
	            count+=(n%base)+1;
	        else if(weight>1)
	            count+=base;
	        base*=10;
	    }
	    return count;
	}
}